<template>
	<div class="addressedit">
		<van-nav-bar title="地址编辑" left-arrow @click-left="onClickLeft" />
		<div class="addressform" v-model="address">
			<van-form @submit="onSubmit">
			  <van-field
			    v-model="address.receiver_name"
			    name="收货人姓名"
			    label="收货人姓名"
			    placeholder="收货人姓名"
			    :rules="[{ required: true, message: '请填写收货人姓名' }]"
			  />
			  <van-field
			    v-model="address.receiver_telephone"
			    name="手机号"
			    label="手机号"
			    placeholder="手机号"
			    :rules="[{ required: true, message: '请填写手机号' }]"
			  />
			  <van-field
			    v-model="address.receiver_address"
			    name="详细地址"
			    label="详细地址"
			    placeholder="详细地址"
			    :rules="[{ required: true, message: '请填写详细地址' }]"
			  />
			  <van-field name="defaultadd" label="默认地址" >
			    <template #input>
			      <van-switch v-model="defaultadd" size="20" />
			    </template>
			  </van-field>
			  <van-field name="radio" label="标签" >
			    <template #input>
			      <van-radio-group v-model="radio" direction="horizontal">
			        <van-radio name="家">家 </van-radio>
			        <van-radio name="学校">学校</van-radio>
					<van-radio name="公司">公司</van-radio>
			      </van-radio-group>
			    </template>
			  </van-field>
			  <div style="margin: 16px;">
			    <van-button round block type="info" native-type="submit">
			      确认修改
			    </van-button>
			  </div>
			</van-form>
		</div>
	</div>
</template>

<script>
	import {
		Toast
	} from 'vant';
	import { Notify } from 'vant';
	export default {
		name: 'AddressEdit',
		data() {
			return {
				address: '',
				radio:'',
				defaultadd:true,
			};
		},
		created() {
			this.address = this.$route.params.address;
			console.log(this.address);
			if(this.address.defult_flag==0){
				this.defaultadd=false;
			}
			if(this.address.receiver_label=='学校'){
				this.radio='学校';
			}else if(this.address.receiver_label=='家'){
				this.radio='家';
			}else if(this.address.receiver_label=='公司'){
				this.radio='公司';
			}
		},
		methods: {
			onSubmit(){
				console.log(this.radio);
				this.address.receiver_label=this.radio;
				if(this.defaultadd==false){
					this.address.defult_flag=0;
				}else{
					this.address.defult_flag=1;
				}
				this.axios.post(`http://localhost:8080//useraddress/modifyaddress`,this.address).then(res => {
					console.log(res.data);
					Notify({ type: 'success', message: '修改成功' });
					this.$router.replace('/personal/address');
					
				});
				Toast('修改成功');
			},
			onClickLeft() {
				this.$router.replace('/personal/address');
			},
			

		},


	}
</script>

<style lang="less">
</style>
